SftTree/OCX 7.0

Using SftTree/OCX with .NET (C#, VB.NET)

Softel vdm, Inc.

Adding SftTree/OCX To The Toolbox

Adding SftTree/OCX To A Project
Adding The SftHelperComponent To A Project
Preparing a Project

Special Considerations
- Indexed Properties
- Picture Properties
- Font Properties
- Color Properties
- Object vs. Interface

Adding SftTree/OCX To The Toolbox

The controls are automatically added to the Visual Studio Toolbox in the toolbox group "Softel vdm, Inc.", except for Visual Studio .NET 2002 and all Visual Studio Express Editions. For these, the controls have to be added "manually" using the simple procedure outlined in "Adding Controls To The Visual Studio Toolbox".

If you are using Visual Studio .NET 2002 or any of the Visual Studio Express Editions, please take a moment to add the controls using the simple procedure outlined in "Adding Controls To The Visual Studio Toolbox" before continuing.

Adding SftTree/OCX To A Project

The SftTree/OCX control can be added to a form, by locating the control in the toolbox group "Softel vdm, Inc.". It can be added to a form by clicking on the SftTree/OCX button of the toolbox, then clicking on the form or by dragging the SftTree/OCX button of the toolbox to the form.

Adding The SftHelperComponent To A Project

In order to be able to use .NET images, color and font properties, a small helper component must be added to each project that uses SftTree/OCX. This helper component assists in to converting OLE types to .NET types.

The SftHelperComponent control can be added to a form, by locating the control in the toolbox group "Softel vdm, Inc.". It can be added to a form by clicking on the SftHelperComponent button of the toolbox, then clicking on the form or by dragging the SftHelperComponent button of the toolbox to the form.

The component will not appear on the form, but will instead be shown as a component used by the form.

Preparing a Project

Add the following Imports and using statements to your project source file(s). This simplifies name resolution, makes most enumerated constants available and provides access to the OLECvt class.

VB

Imports AxSftTreeLib70
Imports SftTreeLib70
Imports Softelvdm.OLEConvert

C#

using SftTreeLib70;
using AxSftTreeLib70;
using Softelvdm.OLEConvert;

All required steps have now been completed to use SftTree/OCX.

 

For a complete example, add the following sample code to initialize the control:

VB

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    ItemIndex = AxSftTree1.Items.Add("Item 1")
    ItemIndex = AxSftTree1.Items.Add("Item 2")
     AxSftTree1.get_Item(ItemIndex).Level = 1
    ItemIndex = AxSftTree1.Items.Add("Item 3")
End Sub

C#

private void Form1_Load(object sender, System.EventArgs e) {
    int itemIndex;
    itemIndex = axSftTree1.Items.Add("Item 1");
    itemIndex = axSftTree1.Items.Add("Item 2");
    axSftTree1.get_Item(itemIndex).Level = 1;
    itemIndex = axSftTree1.Items.Add("Item 3");
}

In this example, the control is initialized at run-time using code. Of course it is also possible (and much easier) to set up all properties using the property pages. You can access the property pages by right-clicking on the control and select the Properties... entry of the popup menu.

You can run the sample application and it displays a SftTree/OCX control with three items.

After adding the control to the form, right click on the control and select the Properties... entry of the popup menu. This displays the Property Dialog for the control.

Please note that you can right-click on a property in a Property Dialog or double-click on the description of a property to access its complete help information

This control has many properties and methods which you can use.  This is a very simple example and doesn't even begin to exploit the capabilities of this control. Please take a moment to familiarize yourself with the objects offered by the SftTree/OCX control.  Each object represents a specific area of the control and can be fully customized. Also make sure to run the demo which is included with this product and take a look at the included samples.

Special Considerations

When adding SftTree/OCX to a project, Visual Studio .NET generates a class wrapper to fully support an ActiveX control such as SftTree/OCX. Unfortunately, this class wrapper is slightly incomplete and generates initially unexpected function names for certain properties. However, these issues are easily resolved.

Indexed Properties

Indexed properties (i.e., properties which require additional parameters, such as an index) are converted into method calls with a get_ and set_ prefix.

For example, the Item property, which requires a subscript (or item index), is used as follows:

AxSftTree1.get_Item(ItemIndex).Level = 1

All other properties with additional parameters use a get_ and set_ prefix. 

The Syntax portion of each method, property and event shows the full syntax, including any prefix (such as get_ and set_, etc.).

Picture Properties

While some graphics properties are generated to use an Image type, many properties and methods do not. These use the OLE picture type stdole.IPictureDisp instead, which cannot directly be used with an Image type.  The Syntax portion of each method, property and event shows the full syntax and required picture type (Image or stdole.IPictureDisp).

The Image type can easily be converted into a stdole.IPictureDisp type using the provided class OLECvt. This class is added to each project using Softelvdm.OLEConvert (see Preparing a Project above).

VB

Public Shared Function ToIPictureDisp(ByVal i As Image) As stdole.IPictureDisp
Public Shared Function ToImage(ByVal pic As stdole.IPictureDisp) As Image

C#

public static stdole.IPictureDisp ToIPictureDisp(Image i);
public static Image ToImage(stdole.IPictureDisp pic);

ToIPictureDisp returns a stdole.IPictureDisp pointer given an Image object.

With this helper class in place, the SftTreeCell.Image property (for example) can now be used as follows:

VB

AxSftTree1.get_Cell(0, 0).Image.Picture = OLECvt.ToIPictureDisp(PictureBox1.Image)

C#

axSftTree1.get_Cell(0,0).Image.Picture = OLECvt.ToIPictureDisp(pictureBox1.Image);

In this example, PictureBox1 is a PictureBox control, part of the form, containing an image.

If you are using the same image many times, make sure to convert it once only and use the saved stdole.IPictureDisp. Converting the same image many times will create multiple OLE Picture objects, which can deplete virtual storage and available systems resources.

The Syntax section of picture properties typically shows Get, Put and PutRef forms. If both Put and PutRef are available, PutRef is the preferred form as it conserves resources and assigns a picture object reference to the control.  Put causes the control to completely copy the picture object.

Font Properties

While some font properties are generated to use a Font type, many properties and methods do not. These use the OLE font type stdole.IFontDisp instead, which cannot directly be used with a Font type.  The Syntax portion of each method, property and event shows the full syntax and required font type (Font or stdole.IFontDisp).

The Font type can easily be converted into a stdole.IFontDisp type using the provided class OLECvt. This class is added to each project using Softelvdm.OLEConvert (see Preparing a Project above).

VB

Public Shared Function ToIFontDisp(ByVal f As Font) As stdole.IFontDisp

C#

public static stdole.IFontDisp ToIFontDisp(Font f);

ToIFontDisp returns an stdole.IFontDisp pointer given a Font object.

With this helper class in place, the SftTreeCell.Font property (for example) can now be used as follows:

VB

Dim NewFont As New Font("Times New Roman", 16, FontStyle.Regular)
AxSftTree1.get_Cell(ItemIndex, 0).Font = OLECvt.ToIFontDisp(NewFont)

C#

Font NewFont = new Font("Times New Roman", 16, FontStyle.Regular);
axSftTree1.get_Cell(0, 0).Font = OLECvt.ToIFontDisp(NewFont);

If you are using the same font many times, make sure to convert it once only and use the saved stdole.IFontDisp. Converting the same font many times will create multiple OLE Font objects, which can deplete virtual storage and available systems resources.

The Syntax section of font properties typically shows Get, Put and PutRef forms. If both Put and PutRef are available, PutRef is the preferred form as it conserves resources and assigns a font object reference to the control. Any change to the font object is reflected in the control also. Put on the other hand causes the control to completely copy the font object.

Color Properties

Color properties without parameters of the SftTree object use the .NET Color structure, but all other properties and objects (such as SftTreeCell, etc.) use the native type UInt32 (uint). Converting a .NET Color structure color to a UInt32 (OLE color value) and vice versa is easily accomplished using the provided class OLECvt. This class is added to each project using Softelvdm.OLEConvert (see Preparing a Project above).

VB

Public Shared Function ToOleColor(ByVal clr As System.Drawing.Color) As UInt32
Public Shared Function ToColor(ByVal clr As UInt32) As System.Drawing.Color

C#

public static uint ToOleColor(System.Drawing.Color clr);
public static System.Drawing.Color ToColor(uint clr);

The valid range for a color value is 0 to 16,777,215 (&HFFFFFF).  The high order byte of a number in this range equals 0; the lower 3 bytes, from least to most significant byte, determine the amount of red, green, and blue, respectively.  The red, green, and blue components are each represented by a number between 0 and 255 (&HFF).  If the high byte is not 0, the system colors as defined in Control Panel's settings are used.  The Windows API GetSysColor defines all valid constants.  Please see your development environment's documentation for applicable color constants.

The Syntax portion of each method and property shows whether a Color structure or an OLE color value is used.

Color Structure - VB

AxSftTree1.BackColor = SystemColors.Highlight
AxSftTree1.BackColor = Color.Red
AxSftTree1.BackColor = OLECvt.ToColor(&HFF) ' red

Dim c As Color
c = AxSftTree1.BackColor

Color Structure - C#

axSftTree1.BackColor = SystemColors.Highlight;
axSftTree1.BackColor = Color.Red;
axSftTree1.BackColor = OLECvt.ToColor(0x00000ff);  // red
Color c = axSftTree1.BackColor;

OLE Color Value - VB

AxSftTree1.get_Cell(0, 0).BackColor = OLECvt.ToOleColor(SystemColors.Highlight)
AxSftTree1.get_Cell(0, 0).BackColor = OLECvt.ToOleColor(Color.Red)
AxSftTree1.get_Cell(0, 0).BackColor = &HFF ' red

Dim c As Color
c = OLECvt.ToColor(AxSftTree1.get_Cell(0, 0).BackColor)

OLE Color Value - C#

axSftTree1.get_Cell(0,0).BackColor = OLECvt.ToOleColor(SystemColors.Highlight);
axSftTree1.get_Cell(0,0).BackColor = OLECvt.ToOleColor(Color.Red);
axSftTree1.get_Cell(0,0).BackColor = 0x00000ff;  // red
Color c = OLECvt.ToColor(axSftTree1.get_Cell(0,0).BackColor);

Object vs. Interface

The main control is represented by an object of the SftTree class, but can also be represented by its ISftTree interface. The ISftTree interface can be retrieved using the Direct property. 

Certain methods and properties have different names and return types, based on how they are accessed. While (for example) an object based on the SftTree class is mostly equivalent to the ISftTree interface exposed by the control, .NET can introduce minor differences. Such differences are shown in the Syntax section of the affected methods and properties.  All other classes are identical to their interfaces and no distinction is made.

The Syntax portion shows both forms, the class member and the interface method (the interface method is always marked with a Note indicator). If both forms are identical, only one entry is shown.

VB, C#

Some properties (particularly font and picture properties) may require different types.  For example, the Font property accepts a System.Drawing.Font when accessed through a SftTree class object, but uses a stdole.IFontDisp interface pointer when accessed directly though the ISftTree interface pointer. stdole.IFontDisp can be provided using the OLECvt class.

Some properties or methods use different names, depending on how they are accessed. For example, the Refresh method is named CtlRefresh when accessed through a SftTree class object. When accessed directly though the ISftTree interface pointer it is named Refresh.

Other classes, such as SftTreeCell and SftTreeHeaders, make no distinction between the class and interface.  The classes SftTreeCell and SftTreeHeaders are equivalent to their respective interfaces ISftTreeCell and ISftTreeHeaders.


Feedback / comments / error reports for this topic
© 2015 - Softel vdm, Inc. - www.softelvdm.com